// store/modules/users.js

const state = {
    users: [
      { id: 1, name: 'Alice', permission: 'admin' },
      { id: 2, name: 'Bob', permission: 'user' },
      { id: 3, name: 'Charlie', permission: 'guest' }
    ]
  };
  
  const getters = {
    getUsers: state => state.users
  };
  
  const actions = {
    addUser({ commit }, newUser) {
      const id = state.users.length + 1;
      commit('ADD_USER', { id, ...newUser });
    },
    deleteUser({ commit }, userId) {
      commit('DELETE_USER', userId);
    },
    updateUserPermission({ commit }, updatedUser) {
      commit('UPDATE_USER_PERMISSION', updatedUser);
    }
  };
  
  const mutations = {
    ADD_USER(state, newUser) {
      state.users.push(newUser);
    },
    DELETE_USER(state, userId) {
      state.users = state.users.filter(user => user.id !== userId);
    },
    UPDATE_USER_PERMISSION(state, updatedUser) {
      const index = state.users.findIndex(user => user.id === updatedUser.id);
      if (index !== -1) {
        state.users[index].permission = updatedUser.permission;
      }
    }
  };
  
  export default {
    state,
    getters,
    actions,
    mutations
  };
  